package gameobjects;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import resources.Sprite;
import tools.Bounds;
import interfaces.Collidable;
import interfaces.Visible;
import abstracts.Level;

public class Teleporter implements Visible, Collidable {
    private final Level LEVEL;
    private final Bounds BOUNDS;
    private final Bounds ADJACENT;
    private final Bounds DEST;
    private static Sprite SPRITE = Sprite.EYEBALL_DOWN;

    public Teleporter(Level level, int row, int col, int destRow, int destCol) {
        LEVEL = level;
        BOUNDS = new Bounds(row, col, 24, 24);
        ADJACENT = new Bounds(row, col, 48, 48);
        DEST = new Bounds(destRow, destCol, 32, 32);
    }

    public final Bounds getDest() {
        return DEST;
    }

    @Override
    public final void draw(final Graphics g) {
        SPRITE.drawAnchored(g, 0, BOUNDS);
        // TODO move this collision check out of the draw event!!!
        for (Collidable other : LEVEL.getCollisionGrid().getCollidables(
                ADJACENT)) {
            if (other instanceof Mage) {
                g.setColor(Color.ORANGE);
                g.setFont(new Font("Georgia", Font.BOLD, 12));
                double width = g.getFontMetrics().getStringBounds(
                        "Press action", g).getWidth();
                g.drawString("Press action",
                        (int) (BOUNDS.getCenterX() - width / 2), (int) BOUNDS
                                .getMinY() - 16);
            }
        }
    }

    @Override
    public final double getDepth() {
        return BOUNDS.getMaxY();
    }

    @Override
    public final Bounds getBounds() {
        return ADJACENT;
    }
}
